package com.barbeque.mall.controller.wx;

import com.barbeque.mall.bean.BaseRespVo;
import com.barbeque.mall.bean.param.CommonData;
import com.barbeque.mall.bean.wx.comment.CommentCount;
import com.barbeque.mall.bean.wx.comment.TopicCommentPageInfo;
import com.barbeque.mall.bean.wx.comment.WxCommentList;
import com.barbeque.mall.bean.wx.comment.WxMarketComment;
import com.barbeque.mall.service.wx.WxCommentService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author why
 * @since 2022/07/21 15:50
 */
@RestController
@RequestMapping("wx/comment")
public class WxCommentController {
    @Autowired
    WxCommentService wxCommentService;

    @RequestMapping("list")
    public BaseRespVo list(Integer valueId, Integer showType,TopicCommentPageInfo info) {
        CommonData<WxCommentList> commentLists = wxCommentService.selectTopicCommentList(valueId,showType,info);
        BaseRespVo<Object> objectBaseRespVo = new BaseRespVo<>();
        objectBaseRespVo.setErrmsg("成功");
        BaseRespVo baseRespVo = BaseRespVo.ok(commentLists);
        return baseRespVo;
    }

    @RequestMapping("post")
    public BaseRespVo post(@RequestBody WxMarketComment wxMarketComment){

        // 此方法中进行插入和查询操作
        // 返回值为查询出的插入数据
       WxMarketComment comment = wxCommentService.insertTopicComment(wxMarketComment);

        return BaseRespVo.ok(comment);
    }

    @RequestMapping("count")
    public BaseRespVo count(byte type,Integer valueId){
        CommentCount commentCount = wxCommentService.selectCommentListCount(valueId);
        BaseRespVo<Object> objectBaseRespVo = new BaseRespVo<>();
        objectBaseRespVo.setErrmsg("成功");
        BaseRespVo baseRespVo = BaseRespVo.ok(commentCount);
        return baseRespVo;

    }
}
